import React,{useState} from 'react'
import axios from 'axios'
import { Toast } from 'react-vant';

function Login() {
  const [phone,setphone]=useState('')
  const [pwd,setpwd]=useState('')
  const tologin=(props)=>{
    let user={phone,pwd}
    axios.post('/login',user).then(res=>{
      if(res.data.code===200){
        localStorage.setItem('user',JSON.stringify(user))
        props.history.go(-1)
      }
      else{
        Toast.fail(res.data.msg)
      }
    })
  }
  return (
    <div className='login'>
      <p>手机号：<input type="text" value={phone} onChange={(e)=>{
        setphone(e.target.value)
      }}/></p>
      <p>密&emsp;码：<input type="text" value={pwd} onChange={(e)=>{
        setpwd(e.target.value)
      }}/></p>
      <button onClick={tologin}>
        登录
      </button>
    </div>
  )
}

export default Login